from abc import ABCMeta, abstractmethod
from main.commons.func_aux import seq_as_string

class Instruction(object):
    
    ARITMETIC = 1
    IO        = 2
    M_ACCES   = 3
    REGISTER  = 4
    
    __metaclass__ = ABCMeta
    
    def __init__(self, params):
        self._params = params
    
    def get_first(self):
        return self._params[0];
    
    def get_second(self):
        return self._params[1];
        
    @abstractmethod
    def run(self, data): pass
    
    @abstractmethod
    def itype(self): pass
    
    def __str__(self):
        return self.__class__.__name__ + ' << ' + seq_as_string(self._params)
    
class Aritmetic(Instruction):
    def itype(self): return Instruction.ARITMETIC
class Register(Instruction):
    def itype(self): return Instruction.REGISTER
class IOInstruction(Instruction):
    def itype(self): return Instruction.IO
    def run(self, **kargs): pass
class MemoryAcces(Instruction):
    def itype(self): return Instruction.M_ACCES
            
class Add(Aritmetic):
    def run(self, **kargs):
        return self.get_first() + self.get_second()
        
class Compare(Aritmetic):
    def run(self, **kargs):
        return self.get_first() == self.get_second()
        
class Move(MemoryAcces):    
    def run(self, **kargs):
        kargs["memory"].set(self.get_first(), self.get_second())

class Jump(Register):
    def run(self, **kargs):
        kargs["Context"].set(self.get_first(), self.get_second())

"""
ADD ;add one number to another number
SUB ;subtract one number to another number
INC ;increment a number by 1
DEC ;decrement a number by 1
MUL ;multiply numbers together
OR  ;boolean algebra function
AND ;boolean algebra function
NOT ;boolean algebra function
XOR ;boolean algebra function
JNZ ;jump to another section of code if a number is not zero (used for loops and ifs)
JZ  ;jump to another section of code if a number is zero (used for loops and ifs)
JMP ;jump to another sect
LDA ;loads the number 12 into the accumulator
STO ;saves the accumulator result (18) to the memory address 34
"""


